home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / devel / eiffel / eiffel_p.z / eiffel_p / ep / ParserDrv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-09  |  4.8 KB  |  231 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <sys/param.h>
  4. #include "ParserDrv.h"
  5. #include "ParserMEY.h"
  6. #include "ParserISE.h"
  7. #include "ParserSIG.h"
  8. #include "Time.h"
  9. #include "ratc.h"
  10.  
  11. extern char scan_errors;
  12.  
  13. bool compatibility;
  14. bool error_out;
  15. bool tree_handling;
  16. bool tree_out;
  17. bool terse;
  18. bool bench_mark;
  19. bool filter;
  20.  
  21. char in_file[MAXPATHLEN], 
  22.      ascii_out_file[MAXPATHLEN],
  23.      binary_out_file[MAXPATHLEN],
  24.      lst_file[MAXPATHLEN], 
  25.      err_file[MAXPATHLEN],
  26.      *command;
  27.  
  28.  
  29. void p_usage() 
  30. {
  31.     fprintf(stderr,"Usage: ep [-MEY|-ISE|-SIG] [-t|-ibfiq] filenames\n");
  32.     exit(1);
  33. }
  34.  
  35.  
  36. void init_val() 
  37. {
  38.     if (terse) {
  39.       if (!(!error_out && !filter && !tree_handling && !tree_handling))
  40.         p_usage();
  41.     }
  42.     else terse = OFF;
  43.     if (!compatibility) compatibility = MEY;
  44.     if (!error_out) error_out = SEPARATE_ERROR;
  45.     if (!tree_handling) tree_handling = WRITETREE;
  46.     if (!tree_out) tree_out = ASCII;
  47. }
  48.  
  49.  
  50.  
  51. void put_tree()
  52. {
  53.     FILE *fp;    
  54.     
  55.       switch (tree_handling) {
  56.       case WRITETREE:
  57.         if (tree_out == ASCII) {
  58.           if (!filter) {
  59.                 if ((fp = fopen(ascii_out_file, "w")) == NULL ) {
  60.                   fprintf(stderr, "%s: can't open %s\n", command, ascii_out_file);
  61.                   exit(1);
  62.                 }
  63.           }
  64.           else 
  65.         fp = stdout;
  66.           WriteTree(fp, TreeRoot);
  67.           if (!filter)
  68.                 fclose(fp);
  69.             }
  70.             else { 
  71.           if (!filter) {
  72.                 if ((fp = fopen(binary_out_file, "w")) == NULL ) {
  73.                   fprintf(stderr, "%s: can't open %s\n", command, binary_out_file);
  74.                   exit(1);
  75.                 }
  76.           }
  77.           else 
  78.         fp = stdout;
  79.           PutTree(fp, TreeRoot);
  80.           if (!filter)
  81.                 fclose(fp);
  82.             }
  83.         break;
  84.       case QUERYTREE:
  85.         QueryTree(TreeRoot);
  86.         break;
  87.       case CHECKTREE:
  88.         CheckTree(TreeRoot);
  89.         break;
  90.       default:
  91.         p_usage();
  92.       }
  93. }  
  94.              
  95.  
  96.  
  97. void handle_err(error_count)
  98. int error_count;
  99. {
  100.     if (!error_count && !scan_errors) { 
  101.       if (terse == OFF) 
  102.         put_tree();
  103.       else 
  104.         fprintf(stderr,"no errors occured!\n");
  105.     }
  106.     else { 
  107.           fprintf(stderr, "%d scan error(s) occured!\n", scan_errors);
  108.           fprintf(stderr, "%d parse error(s) occured!\n", error_count);
  109.       if (error_out == INTEGRATED_ERROR) {
  110.         fprintf(stderr," Generating Listing: %s\n", lst_file);
  111.         gen_lst();
  112.       }
  113.     }
  114. }
  115.  
  116.  
  117. void Parser() {
  118. int error_count;
  119.     if (error_out == INTEGRATED_ERROR)
  120.       StoreMessages(ON);
  121.     if (!filter)
  122.       fprintf(stderr, "Analysing %s.\n", in_file);
  123.     switch (compatibility) {
  124.     case MEY:
  125.          error_count = ParserMEY();
  126.          break;
  127.     case ISE: 
  128.          error_count = ParserISE();
  129.          break;
  130.     case SIG:
  131.          error_count = ParserSIG();
  132.          break;
  133.  
  134.     default :
  135.          p_usage();
  136.         }
  137.     handle_err(error_count);
  138. }
  139.  
  140. void inout_files(fname)
  141. char *fname;
  142. {
  143.     bzero(lst_file, MAXPATHLEN);
  144.     bzero(err_file, MAXPATHLEN);
  145.     bzero(in_file, MAXPATHLEN);
  146.     bzero(ascii_out_file, MAXPATHLEN);
  147.     bzero(binary_out_file, MAXPATHLEN);
  148.     if (!strcmp(fname+(strlen(fname)-2), ".e")) {
  149.       strcpy(in_file, fname);
  150.       strcat(strncpy(lst_file, in_file, strlen(in_file)-1), "lst");
  151.       strcat(strncpy(err_file, in_file, strlen(in_file)-1), "err");
  152.       strcat(strncpy(ascii_out_file, in_file, strlen(in_file)-1), "atr");
  153.       strcat(strncpy(binary_out_file, in_file, strlen(in_file)-1), "btr");
  154.     }
  155.     else {
  156.       strcpy(in_file, fname);
  157.       strcat(in_file, ".e");
  158.       strcat(strcat(lst_file, fname), ".lst");
  159.       strcat(strcat(err_file, fname), ".err");
  160.       strcat(strcat(ascii_out_file, fname), ".atr");
  161.       strcat(strcat(binary_out_file, fname), ".btr");
  162.     }
  163. }
  164.  
  165.  
  166. int main(argc, argv) 
  167. int argc;
  168. char **argv;
  169. {
  170.     int i = 0;
  171.     char *opt_ptr;
  172.  
  173.     command = argv[0];
  174.     while ( (++i < argc) && (*(argv[i]) == '-') ) {
  175.       if (strcmp(argv[i]+1, "MEY") == 0)
  176.         if (!compatibility) compatibility = MEY;    
  177.         else  p_usage();
  178.       else 
  179.             if (strcmp(argv[i]+1, "ISE") == 0)
  180.           if (!compatibility) compatibility = ISE;
  181.           else p_usage();
  182.         else 
  183.               if (strcmp(argv[i]+1, "SIG") == 0)
  184.         if (!compatibility) compatibility = SIG;
  185.         else p_usage();
  186.           else {
  187.         opt_ptr = argv[i]+1;
  188.         opt_ptr--;
  189.         while (*(++opt_ptr) ) {
  190.           switch (*opt_ptr) {
  191.           case 't':
  192.                            terse = ON;
  193.                break;
  194.           case 'i':
  195.                error_out = INTEGRATED_ERROR;
  196.                break;
  197.           case 'q':
  198.                tree_handling = QUERYTREE;
  199.                break;
  200.           case 'c':
  201.                tree_handling = CHECKTREE;
  202.                break;
  203.           case 'b': 
  204.                tree_out = BIN;
  205.                break;
  206.           case 'f' :
  207.                filter = ON;
  208.                   break;
  209.           case 'B':
  210.                bench_mark = ON;
  211.                  break;
  212.           default :
  213.                p_usage();
  214.           }
  215.             }
  216.           } 
  217.            }
  218.     init_val();
  219.     i--;
  220.     while ( ++i < argc ) {
  221.       inout_files(argv[i]);
  222.       if (bench_mark)
  223.         (void) StepTime();
  224.       ReleaseTreeModule();
  225.       Parser();
  226.       if (bench_mark)
  227.         WriteStepTime("milliseconds:");
  228.     }
  229.     return 0;
  230. }
  231.